(function() {

this.codium = this.codium || {};
this.codium.control = this.codium.control || {};

this.codium.control.MessageList = pasta.webgui.ContainerControl.extend(
{
	init : function() 
	{
		this._super();
		
		this.msgCount = 0;
		
		this.clientCanvas.style.position = "relative";
		this.clientCanvas.style.overflow = "auto";
	},
	
	clear : function()
	{
		this.clientCanvas.innerHTML = "";
		this.msgCount = 0;
	},
	
	addMessage : function(title, poster, time, message)
	{
		var bgColor = ((this.msgCount % 2) == 1) ? "#ECECEC" : "#FFFFFF";
		
		var html = "<div style='border-bottom: 1px solid #888888; background: " + bgColor + "'>" +
						"<div style='height:8px'>&nbsp;</div>" +
						"<div style='font-weight:bold;color:#7F0000;font-size:13px'><u>" + title + "</u></div>" +
						"<div style='color:#AAAAAA;font-size:12px'>by " + poster + " at " + time + "</div>" +
						"<div style='height:8px'>&nbsp;</div>" +
						"<div style='color:#000000;font-size:12px'>" + this.translateMsg(message) + "</div>" +
						"<div style='height:8px'>&nbsp;</div>" +
					"</div>";
		
		this.clientCanvas.innerHTML += html;
		this.msgCount++;
	},
	
	translateMsg : function(str)
	{
		var result = str;
		
		var pos = result.indexOf("\r\n");
		
		while (pos > 0)
		{
			result = result.replace("\r\n", "<br>");
			pos = result.indexOf("\r\n");
		}
		
		pos = result.indexOf("\r");
		
		while (pos > 0)
		{
			result = result.replace("\r", "<br>");
			pos = result.indexOf("\r");
		}
		
		pos = result.indexOf("\n");
		
		while (pos > 0)
		{
			result = result.replace("\n", "<br>");
			pos = result.indexOf("\n");
		}
		
		return result;
	},
	
	//------------------ Event Handler -----------------
	
	//------------------ Setter & Getter -----------------
	
});

})();